﻿using mars_client.csharp.cache;
using mars_client.csharp.enums;
using mars_client.csharp.model;
using mars_client.csharp.model.vo;
using mars_client.csharp.radar;
using mars_client.csharp.util;
using mars_client.csharp.vo;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace mars_client.gui.page
{
    /// <summary>
    /// SingleChat.xaml 的交互逻辑
    /// </summary>
    public partial class SingleChatPage : Page
    {
        public SingleChatPage()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 创建人   : Cecil0o0
        /// 电子邮箱 : jiegithub@gmail.com
        /// 创建时间 : 2016-2-27
        /// 功能描述 : 初始化接口。
        /// 1. 通过单独聊天的主键获取所有的聊天内容
        /// 2. 获取对方的基本信息(如头像url，姓名，别称等)
        /// </summary>
        /// <param name="uuid"></param>
        public void initData()
        {
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            sendMessage();
        }
        private void sendMessage()
        {
            MessageCO messageCO = new MessageCO();
            messageCO.type = (int)RequestEnum.request.SingleChatContent;
            SingleChatVO singleChatVO = new SingleChatVO();

            singleChatVO.messageVO = new MessageVO();
            singleChatVO.receiverVO = new UserVO();
            singleChatVO.senderVO = new UserVO();

            singleChatVO.receiverVO.id = long.Parse(this.Uid);
            singleChatVO.senderVO.id = UserCache.Instance.userVO.id;
            singleChatVO.messageVO.message = sendText.Text;
            messageCO.content = singleChatVO;

            Radar.Instance.sendData(messageCO);

            SingleChatVO singleChatVO1 = new SingleChatVO();
            singleChatVO1.senderVO = UserCache.Instance.userVO;
            singleChatVO1.receiverVO = new UserVO();
            singleChatVO1.messageVO = new MessageVO();

            singleChatVO1.sendTime = DateTime.Now.ToLongTimeString().ToString();
            singleChatVO1.messageVO.message = sendText.Text;
            this.contentWrapper.Children.Add(RenderUtil.generateChatTemp(singleChatVO1, "right"));

            sendText.Text = "";
        }

        private void selectFile(object sender, MouseButtonEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "*.jpeg | *.jpg";
            ofd.ShowDialog();
            if(ofd.FileName != null && ofd.FileName != "")
            {
                MessageCO messageCO = new MessageCO();
                messageCO.type = (int)RequestEnum.request.SingleChatContent;
                MessageVO messageVO = new MessageVO();
                messageVO.image = TransformUtil.GetBytesFromFile(ofd.FileName);
                messageCO.content = messageVO;
                Radar.Instance.sendData(messageCO);
            }
        }

        private void sendText_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                sendMessage();
        }
    }
}
